import 'package:get/get.dart';

class MyPutController extends GetxController {
  //Int
  RxInt count = 0.obs;
  var count1 = 0.obs;

  //String
  RxString audi = "Audi".obs;
  var audi1 = "Audi".obs;

  //List
  RxList<String> list = ["Audi", "BMW", "Mercedes"].obs;
  var list1 = ["Audi", "BMW", "Mercedes"].obs;

  //Map
  RxMap<String, String> map = {"Audi": "Audi", "BMW": "BMW", "Mercedes": "Mercedes"}.obs;
  var map1 = {"Audi": "Audi", "BMW": "BMW", "Mercedes": "Mercedes"}.obs;

  //Models
  RxList<GetXModels> models = [GetXModels(name: "Audi"), GetXModels(name: "BMW"), GetXModels(name: "Mercedes")].obs;
  var models1 = [GetXModels(name: "Audi"), GetXModels(name: "BMW"), GetXModels(name: "Mercedes")].obs;

  //Model
  Rx<GetXModels> model = GetXModels(name: "Audi").obs;
  var model1 = GetXModels(name: "Audi").obs;

  //GetXRxModels
  RxList<GetXRxModels> rxModels =
      [GetXRxModels(name: "Audi".obs), GetXRxModels(name: "BMW".obs), GetXRxModels(name: "Mercedes".obs)].obs;
  var rxModels1 =
      [GetXRxModels(name: "Audi".obs), GetXRxModels(name: "BMW".obs), GetXRxModels(name: "Mercedes".obs)].obs;

  //bool
  RxBool isTrue = true.obs;
  var isTrue1 = true.obs;

  updateCount() {
    count.value++;
    count1.value++;
  }

  updateAudi() {
    audi.value = "BMW";
    audi1.value = "BMW";
  }

  updateList() {
    list[0] = "BMW";
    list1[0] = "BMW";
  }

  updateMap() {
    map["Audi"] = "BMW";
    map1["Audi"] = "BMW";
  }

  updateModels() {
    models[0] = GetXModels(name: "BMW");
    models1[0] = GetXModels(name: "BMW");
  }

  updateModel() {
    model.value = GetXModels(name: "BMW");
    model1.value = GetXModels(name: "BMW");
  }

  updateRxModels() {
    rxModels[0].name.value = "BMW";
    rxModels1[0].name.value = "BMW";
  }

  updateIsTrue() {
    isTrue.value = !isTrue.value;
    isTrue1.value = !isTrue1.value;
  }

  updateAll() {
    updateCount();
    updateAudi();
    updateList();
    updateMap();
    updateModels();
    updateModel();
    updateIsTrue();
    updateRxModels();
  }
}

class GetXModels {
  String name;
  GetXModels({required this.name});
}

class GetXRxModels {
  RxString name;
  GetXRxModels({required this.name});
}


/**
 * 监听整个列表的变化：
如果你想要监听整个列表的变化（比如添加或删除Person对象），你可以使用observe方法。但是，如果你只想监听列表中某个Person对象的name变化，你通常不需要直接监听列表，因为Person对象的name属性已经是响应式的。
dart
people.observe(initial: false, onChange: (List<Person> list) {  
  // 这里会触发当列表本身发生变化时，比如添加或删除元素  
  print("List changed");  
});

在你的UI中，你可以直接使用people列表中的Person对象的name属性，GetX会确保当这些属性变化时，UI会相应地更新。
Obx(() => ListView.builder(  
  itemCount: people.length,  
  itemBuilder: (_, index) => Text(  
    people[index].name.value,  
    style: TextStyle(fontSize: 20),  
  ),  
));

修改Person对象的name：
当你修改列表中某个Person对象的name时，不需要做任何特别的事情来触发监听。由于name是RxString，任何对它的修改都会自动被GetX捕获并触发UI更新。
void changeName(int index, String newName) {  
  people[index].name.value = newName;  
}
 */